home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / Demos / Herois / Codigo.Cst / 00036_Script_ControlaUniverso < prev    next >
Text File  |  1999-03-19  |  7KB  |  218 lines

  1. property sprPrimeiro  -- Primeiro dos 12 sprites que compoe universo
  2. property memPrimeiro  -- Primeiro membro
  3. property velMaxima    -- Velocidade em pixels/s
  4. property puloMaximo   -- Pulo maximo em pixels
  5. property areaX, areaY -- Tamanho da area de sensibilidade nos cantos
  6.  
  7. property intMemPrimeiro -- Numero do primeiro membro
  8. property ultimoX, ultimoY -- Para verificar se precisa atualizar posicao
  9. property bScrolling -- Se esta scrollando
  10. property cronoScrolling -- Cronometro do controle de scroll
  11. property numIcones, sprIcones, posIcones, sprOutros
  12. property memoria, limitado
  13.  
  14. on getBehaviorDescription
  15.   return "Controle dos sprites do universo"
  16. end
  17.  
  18. on getPropertyDescriptionList
  19.   set p_list = [ ¼
  20.     #sprPrimeiro: [ #comment: "Primeiro dos 12 sprites que compoe"¼
  21.                               & " universo", ¼
  22.                      #format: #integer, ¼
  23.                     #default: 1 ],¼
  24.     #memPrimeiro: [ #comment: "Primeiro membro do universo dividido"¼
  25.                               & " em 10 pedacos", ¼
  26.                      #format: #string, ¼
  27.                     #default: "Universo1"    ], ¼
  28.     #velMaxima: [ #comment: "Velocidade maxima (pixels/s)",¼
  29.                      #format: #integer, ¼
  30.                     #default: 5 ],¼
  31.     #puloMaximo: [ #comment: "Pulo maximo (pixels)",¼
  32.                      #format: #integer, ¼
  33.                     #default: 40 ],¼
  34.     #areaX: [ #comment: "Tamanho da area sensivel de scroll nas bordas",¼
  35.                      #format: #integer, ¼
  36.                     #default: 80 ],¼
  37.     #areaY: [ #comment: "Tamanho da area sensivel de scroll nas bordas",¼
  38.                      #format: #integer, ¼
  39.                     #default: 40 ],¼
  40.     #numIcones: [ #comment: "Numero de Icones",¼
  41.                      #format: #integer, ¼
  42.                     #default: 7 ],¼
  43.     #sprIcones: [ #comment: "Primeiro sprite dos icones",¼
  44.                      #format: #integer, ¼
  45.                     #default: 24 ],¼
  46.     #memoria: [ #comment: "Limite de memoria para scrollar",¼
  47.                      #format: #integer, ¼
  48.                     #default: 0 ]¼
  49.   ]
  50.   return p_list
  51. end
  52.  
  53. on beginSprite me
  54.   put the number of member memPrimeiro into intMemPrimeiro
  55.   set sprOutros = 22
  56.   -- Acerta icones
  57.   set posIcones = espalha(numIcones,1440,960)
  58.   -- Posiciona sprites
  59.   posiciona me, 0, 0
  60.   put 0 into ultimoX
  61.   -- Levanta cortina
  62.   repeat with i = sprPrimeiro to sprPrimeiro + 19
  63.     set the visible of sprite i to true
  64.   end repeat
  65.   -- Scrolling
  66.   put false into bScrolling
  67.   
  68.   global myMemSize
  69.   if myMemSize <= memoria * 1024 * 1024 then
  70.     set limitado = true
  71.   else
  72.     set limitado = false
  73.   end if
  74.   
  75.   -- Atualiza 
  76.   updateStage
  77. end
  78.  
  79. on cleanSprite me
  80.   global gPronde
  81.   if gPronde <> 1 then
  82.     repeat with i = sprPrimeiro to sprPrimeiro + 19
  83.       puppetSprite i,false
  84.     end repeat
  85.   end if
  86. end
  87.  
  88. on clicaIcone me, num
  89.   sendSprite 120, #comecaAnima
  90.   updateStage
  91.   cursor 4
  92.   vaiPagina num, true
  93.   cursor -1
  94. end
  95.  
  96. on vaiIcone me, num
  97.   set ultimoX = 320 - the locH of getAt(posIcones,num)
  98.   set ultimoY = 240 - the locV of getAt(posIcones,num)
  99.   posiciona me, ultimoX, ultimoY
  100. end
  101.  
  102. on posiciona me, x, y
  103.   -- Icones
  104.   repeat with i = 1 to numIcones
  105.     set ix = the locH of getAt(posIcones,i)
  106.     set ix = (ix + x) mod 1440
  107.     if ix < 0 then set ix = ix + 1440
  108.     if ix > 900 then set ix = ix - 1440
  109.     set iy = the locV of getAt(posIcones,i)
  110.     set iy = (iy + y) mod 960
  111.     if iy < 0 then set iy = iy + 960
  112.     if i < 7 or the frame < marker("UniUltra") then
  113.       set the loc of sprite (sprIcones + i - 1) to point(ix,iy)
  114.       set the loc of sprite (sprOutros + i - 1) to point(ix,iy)
  115.     end if
  116.     --    if i = 4 then put " -- > (" & y & ") "  & iy & " =? " & the locV of sprite (sprIcones + i - 1)
  117.   end repeat
  118.   
  119.   -- Normaliza X
  120.   put x mod 1440 into x
  121.   if x < 0 then put x + 1440 into x
  122.   -- Normaliza Y
  123.   put y mod 480 into y
  124.   if y < 0 then put y + 480 into y
  125.   put y - 480 into y
  126.   put sprPrimeiro into spr
  127.   repeat with i_y = 1 to 2
  128.     put x into pos_x
  129.     put (pos_x + 71) / 72 into tmp
  130.     put pos_x - 72 * tmp into pos_x
  131.     put 20 - tmp into mem
  132.     repeat with i_x = 1 to 10
  133.       puppetSprite spr, true
  134.       put mem mod 20 into mem
  135.       set the memberNum of sprite spr to mem + intMemPrimeiro
  136.       put mem+1 into mem
  137.       set the loc of sprite spr to point(pos_x+36,y+240)
  138.       put spr+1 into spr
  139.       put 72+pos_x into pos_x
  140.     end repeat
  141.     put 480 + y into y
  142.   end repeat
  143.   
  144.   
  145. end
  146.  
  147. on idleSprite me
  148.   if limitado then return
  149.   
  150.   global gMustUpdate, gCritico
  151.   if rollOver(the spriteNum of me) and gCritico = 0 then
  152.     -- Captura mouse
  153.     put the mouseH into x
  154.     put the mouseV into y
  155.     -- Pega raios
  156.     put abs(x - 320) - 320 + areaX into rx
  157.     if rx > areaX then put areaX into rx
  158.     put abs(y - 240) - 180 + areaY into ry
  159.     if ry > areaY then put areaY into ry
  160.     -- Calcula velocidades
  161.     --    put "rx=" & rx & ", ry=" & ry
  162.     if rx > 0 then
  163.       put rx * velMaxima / areaX into velX
  164.     else
  165.       put 0 into velX
  166.     end if
  167.     if ry > 0 then
  168.       put ry * velMaxima / areaY into velY
  169.     else
  170.       put 0 into velY
  171.     end if
  172.     --    put "velX=" & velX & ", velY=" & velY
  173.     -- Calcula quantidades de scroll
  174.     if velX > 0 or velY > 0 then
  175.       if bScrolling then
  176.         put the timer into agora
  177.         put (agora - cronoScrolling) into passou
  178.         put velX * passou / 100 into dx
  179.         if velX > 0 and dx = 0 then put 1 into dx
  180.         put velY * passou / 100 into dy
  181.         if velY > 0 and dy = 0 then put 1 into dy
  182.         put dx * dx + dy * dy into dtotal
  183.         put puloMaximo * puloMaximo into dtmp
  184.         if dtotal > dtmp then
  185.           put sqrt(dtotal) into dtotal
  186.           put dx * puloMaximo / dtotal into dx
  187.           put dy * puloMaximo / dtotal into dy
  188.         end if
  189.         if x < 320 then
  190.           put ultimoX - dx into ultimoX
  191.         else
  192.           put ultimoX + dx into ultimoX
  193.         end if
  194.         if y < 240 then
  195.           put ultimoY - dy into ultimoY
  196.         else
  197.           put ultimoY + dy into ultimoY
  198.         end if
  199.         posiciona me, ultimoX, ultimoY
  200.         set gMustUpdate = true
  201.         put agora into cronoScrolling
  202.       else
  203.         put the timer into cronoScrolling
  204.         put true into bScrolling
  205.       end if
  206.     else
  207.       -- Se fora da area de sensivel
  208.       put false into bScrolling
  209.     end if
  210.   else
  211.     -- Se nem sobre imagem esta
  212.     put false into bScrolling
  213.   end if
  214. end
  215.  
  216.  
  217.  
  218.